home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / comm4.c < prev    next >
C/C++ Source or Header  |  1993-11-15  |  46KB  |  1,667 lines

  1. /***********************************************************************/
  2. /* COMM4.C - Commands P-S                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\comm4.c 1.4 1993/09/01 16:25:43 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. #ifdef UNIX
  51. #include <signal.h>
  52. #endif
  53.  
  54. /*#define DEBUG 1*/
  55.  
  56. /*-------------------------- external data ----------------------------*/
  57. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  58. extern char current_screen;
  59. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  60. extern char display_screens;                      /* number of screens */
  61. extern char number_of_views;                   /* number of open files */
  62. extern bool horizontal;
  63. extern char current_file;         /* pointer to current file */
  64. extern WINDOW *foot,*error_window,*divider;
  65. extern bool error_on_screen;
  66. extern char *rec;
  67. extern unsigned short rec_len;
  68. extern char *cmd_rec;
  69. extern unsigned short cmd_rec_len;
  70. extern char *pre_rec;
  71. extern unsigned short pre_rec_len;
  72. extern char *tempfilename;
  73.  
  74. extern char *temp_cmd;
  75. extern char dir_filename[10];
  76. extern char dir_pathname[MAX_FILE_NAME+1];
  77. extern char curr_path[MAX_FILE_NAME+1] ;
  78. extern char sp_path[MAX_FILE_NAME+1] ;
  79. extern char sp_fname[MAX_FILE_NAME+1] ;
  80. extern char dir_path[MAX_FILE_NAME+1] ;    /* for dir and ls commands */
  81. extern short save_coord_x[VIEW_WINDOWS];
  82. extern short save_coord_y[VIEW_WINDOWS];
  83. /*man-start*********************************************************************
  84. COMMAND
  85.      print - send text to default printer or print spooler
  86.  
  87. SYNTAX
  88.      PRint [target] [n]
  89.      PRint LINE [text]
  90.      PRint STRING [text]
  91.      PRint FORMfeed
  92.      PRint CLOSE
  93.  
  94. DESCRIPTION
  95.      The PRINT command writes a portion of the current file to the default
  96.      printer or print spooler, or text entered on the command line.
  97.   
  98.      PRINT [target] [n]
  99.         Sends text from the file contents up to the target to the printer
  100.         followed by a CR/LF (DOS) or LF(UNIX) after each line.
  101.         When [n] is specified, this sends a formfeed after [n] successive
  102.         lines of text.
  103.      PRINT LINE [text]
  104.         Sends the remainder of the text on the command line to the printer
  105.         followed by a CR/LF (DOS) or LF(UNIX).
  106.      PRINT STRING [text]
  107.         Sends the remainder of the text on the command line to the printer
  108.         without any trailing line terminator.
  109.      PRINT FORMFEED
  110.          Sends a formfeed (^L) character to the printer.
  111.      PRINT CLOSE
  112.          Closes the printer spooler.
  113.  
  114. COMPATIBILITY
  115.      XEDIT: N/A
  116.      KEDIT: Compatible.
  117.  
  118. SEE ALSO
  119.      printer
  120.  
  121. STATUS
  122.      Incomplete. OS/2 version does not work.
  123. **man-end**********************************************************************/
  124. #ifdef PROTO
  125. int Print(char *params)
  126. #else
  127. int Print(params)
  128. char *params;
  129. #endif
  130. /***********************************************************************/
  131. {
  132. /*--------------------------- local data ------------------------------*/
  133. #define PRT_PARAMS  2
  134.  char *word[PRT_PARAMS+1];
  135.  unsigned short num_params;
  136.  long num_lines;
  137. /*--------------------------- processing ------------------------------*/
  138. #ifdef TRACE
  139.  trace_function("comm4.c:   Print");
  140. #endif
  141.  num_params = param_split(params,word,PRT_PARAMS,WORD_DELIMS,TEMP_PARAM);
  142.  if (num_params == 0)
  143.    {
  144.     num_params = 1;
  145.     word[0] = (char *)"1";
  146.    }
  147.  post_process_line(CURRENT_VIEW->focus_line);
  148.  if (equal((char *)"line",word[0],4))
  149.     print_line(NO,0L,0,(char *)word[1],
  150.               (char *)"\r\n",FALSE);
  151.  else
  152.     if (equal((char *)"string",word[0],5))
  153.        print_line(NO,0L,0,(char *)word[1],(char *)"",FALSE);
  154.     else
  155.        if (equal((char *)"formfeed",word[0],4))
  156.          {
  157.           if (num_params > 1)
  158.             {
  159.              display_error(1,word[1]);
  160. #ifdef TRACE
  161.              trace_return();
  162. #endif
  163.              return(RC_INVALID_OPERAND);
  164.             }
  165.           print_line(NO,0L,0,(char *)"",(char *)"\f",FALSE);
  166.          }
  167.        else
  168.           if (equal((char *)"close",word[0],5))
  169.             {
  170.              if (num_params > 1)
  171.                {
  172.                 display_error(1,word[1]);
  173. #ifdef TRACE
  174.                 trace_return();
  175. #endif
  176.                 return(RC_INVALID_OPERAND);
  177.                }
  178.              print_line(YES,0L,0,(char *)"",(char *)"",FALSE);
  179.             }
  180.           else
  181.             {
  182.              if ((num_lines = valid_target(word[0],get_true_line())) == TARGET_ERROR)
  183.                {
  184.                 display_error(4,word[0]);
  185. #ifdef TRACE
  186.                 trace_return();
  187. #endif
  188.                 return(RC_INVALID_OPERAND);
  189.                }
  190.              if (num_params < 2)
  191.                 word[1] = (char *)"0";
  192.              if (valid_positive_integer(word[1]) == NO)
  193.                {
  194.                 display_error(4,word[0]);
  195. #ifdef TRACE
  196.                 trace_return();
  197. #endif
  198.                 return(RC_INVALID_OPERAND);
  199.                }
  200.              print_line(NO,num_lines,atoi(word[1]),(char *)"",
  201.                         (char *)"\r\n",
  202.                         (equal((char *)"all",word[0],3) ? TRUE : FALSE));
  203.             }
  204. #ifdef TRACE
  205.  trace_return();
  206. #endif
  207.  return(RC_OK);
  208. }
  209. /*man-start*********************************************************************
  210. COMMAND
  211.      put - write part of a file to another
  212.  
  213. SYNTAX
  214.      PUT [target] [fileid]
  215.  
  216. DESCRIPTION
  217.      The PUT command writes a portion of the current file to another
  218.      file, either explicit or temporary.
  219.      When no fileid is supplied the temporary file is overwritten.
  220.      When a fileid is supplied the portion of the file written out
  221.      is appended to the specified file.
  222.  
  223. COMPATIBILITY
  224.      XEDIT: Compatible.
  225.      KEDIT: Compatible.
  226.  
  227. SEE ALSO
  228.      putd,get
  229.  
  230. STATUS
  231.      Complete.
  232. **man-end**********************************************************************/
  233. #ifdef PROTO
  234. int Put(char *params)
  235. #else
  236. int Put(params)
  237. char *params;
  238. #endif
  239. /***********************************************************************/
  240. {
  241. /*--------------------------- local data ------------------------------*/
  242.  int rc;
  243. /*--------------------------- processing ------------------------------*/
  244. #ifdef TRACE
  245.  trace_function("comm4.c:   Put");
  246. #endif
  247.  rc = execute_put(params,FALSE);
  248. #ifdef TRACE
  249.  trace_return();
  250. #endif
  251.  return(rc);
  252. }
  253. /*man-start*********************************************************************
  254. COMMAND
  255.      putd - write part of a file to another and delete
  256.  
  257. SYNTAX
  258.      PUTD [target] [fileid]
  259.  
  260. DESCRIPTION
  261.      The PUTD command writes a portion of the current file to another
  262.      file, either explicit or temporary and deletes those lines written.
  263.      When no fileid is supplied the t